package com.wzz.common.utils;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

public class UIEvent {
  @SuppressWarnings("unused")
  private static final String TAG = "UIEvent";

  private List<Handler> needToReflashList = null;

  private static UIEvent uiEvent = null;

  public static UIEvent getInstance() {
    if (uiEvent == null) {
      uiEvent = new UIEvent();
    }
    return uiEvent;
  }

  private UIEvent() {
    needToReflashList = new ArrayList<Handler>();
  }

  public void register(Handler item) {
    needToReflashList.add(item);
  }

  public void remove(Handler item) {
    needToReflashList.remove(item);
  }

  public void notifications() {
    if (needToReflashList == null && needToReflashList.isEmpty()) {
      return;
    } else {
      for (Handler item : needToReflashList) {
        item.sendEmptyMessage(1);
      }
    }
  }

  public void notifications(int flag) {
    if (needToReflashList == null && needToReflashList.isEmpty()) {
      return;
    } else {
      for (Handler item : needToReflashList) {
        item.sendEmptyMessage(flag);
      }
    }
  }
  public void notifications(Message msg) {
    if (needToReflashList == null && needToReflashList.isEmpty()) {
      return;
    } else {
      for (Handler item : needToReflashList) {
        item.sendMessage(msg);
      }
    }
  }
  public void notifications(int flag, int now, int max) {
    if (needToReflashList == null && needToReflashList.isEmpty()) {
      return;
    } else {
      for (Handler item : needToReflashList) {
        Message a = Message.obtain();
        a.what = flag;
        a.arg1 = now;
        a.arg2 = max;
        item.sendMessage(a);
      }
    }
  }
  public void notifications(int flag, int arg1, int arg2,Object obj) {
    if (needToReflashList == null && needToReflashList.isEmpty()) {
      return;
    } else {
      for (Handler item : needToReflashList) {
        Message a = Message.obtain();
        a.what = flag;
        a.arg1 = arg1;
        a.arg2 = arg2;
        a.obj = obj;
        item.sendMessage(a);
      }
    }
  }
  public void notifications(int flag, String url,String path) {
    if (needToReflashList == null && needToReflashList.isEmpty()) {
      return;
    } else {
      for (Handler item : needToReflashList) {
        Message a = Message.obtain();
        a.what = flag;
        Bundle data = new Bundle();
        data.putString("url", url);
        data.putString("path", path);
        a.setData(data);
//        
//        a.arg1 = arg1;
//        a.arg2 = arg2;
//        a.obj = obj;
        item.sendMessage(a);
      }
    }
  }
}
